home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / smallt~1 / smallt~1.zoo / mst.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-26  |  6.8 KB  |  275 lines

  1. /***********************************************************************
  2.  *
  3.  *    Generic inclusions.
  4.  *
  5.  ***********************************************************************/
  6.  
  7. /***********************************************************************
  8.  *
  9.  * Copyright (C) 1988, 1989, 1990 Free Software Foundation, Inc.
  10.  * Written by Steve Byrne.
  11.  *
  12.  * This file is part of GNU Smalltalk.
  13.  *
  14.  * GNU Smalltalk is free software; you can redistribute it and/or modify it
  15.  * under the terms of the GNU General Public License as published by the Free
  16.  * Software Foundation; either version 1, or (at your option) any later 
  17.  * version.
  18.  * 
  19.  * GNU Smalltalk is distributed in the hope that it will be useful, but WITHOUT
  20.  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
  21.  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  22.  * more details.
  23.  * 
  24.  * You should have received a copy of the GNU General Public License along with
  25.  * GNU Smalltalk; see the file COPYING.  If not, write to the Free Software
  26.  * Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  
  27.  *
  28.  ***********************************************************************/
  29.  
  30.  
  31. /*
  32.  *    Change Log
  33.  * ============================================================================
  34.  * Author      Date       Change 
  35.  * sbyrne    23 Sep 89      Modifications to support operation on a DECstation 3100.
  36.  *
  37.  * sbyrne    13 Sep 89      Sigh!!! modified pushOOP and setStackTop to move the
  38.  *              objects that they refer to to toSpace...good bye
  39.  *              performance!
  40.  *
  41.  * sbyrne    29 Dec 88      Created.
  42.  *
  43.  */
  44.  
  45. #ifndef __MST__
  46. #define __MST__
  47.  
  48. #include "mstconfig.h"
  49.  
  50. /* The system version flags */
  51. #define sysVersMajor        1 
  52. #define sysVersMinor        1 
  53.  
  54. /* Enable this definition to count different types of byte code executions */
  55. /* #define countingByteCodes */
  56.  
  57.  
  58. #define baseInt            (((unsigned long)3)<<30)
  59. #define highBitMask        (((unsigned long)1)<<31) /* just hi bit */
  60.  
  61. #ifndef USE_BCOPY
  62. #include <memory.h>
  63. #define bcopy(s2, s1, n)  memcpy(s1, s2, n)
  64. #define bzero(s,l) memset(s,'\0',l)
  65. #endif /* USE_BCOPY */
  66.  
  67. /*#if !defined(__STDC__) && (defined(AIX) | defined(mips) | defined(ibm032) || (defined(sun) && !defined(SUNOS40))) */
  68. #if !defined(__STDC__) && defined(OLDCC)
  69. /* for older compilers that don't understand void * and enums are ints */
  70. #define nil            0
  71. typedef char *voidPtr;
  72. #define ENUM_INT(x)           ((int)(x))
  73. typedef int Boolean;
  74. #define false            0
  75. #define true            1
  76.  
  77. #else 
  78. typedef void *voidPtr;
  79. #define nil            (voidPtr)0
  80. #define ENUM_INT(x)        (x)
  81.  
  82. typedef enum booleanType {
  83.   false,
  84.   true
  85. } Boolean;
  86.  
  87. #endif
  88.  
  89.  
  90. /* Would someone (this means you!) please test this out on this machine and 
  91.  * see if this can be merged with the code above a little more cleanly?
  92.  */
  93. #if defined(hp9000s300)
  94. #undef ENUM_INT
  95. #define ENUM_INT(x)            ((int)(x))
  96. #endif
  97.  
  98. /* The set of checks here should either be expanded, or in the m-*.h files
  99.    there should be a definition that talks about the required alignment
  100.    for doubles, whether they must be on a 4 or 8 byte boundary. */
  101. #if defined(sparc) || defined(hppa)
  102. #define DOUBLE_ALIGNMENT    sizeof(double)
  103. #else
  104. #define DOUBLE_ALIGNMENT    sizeof(long)
  105. #endif
  106.  
  107.  
  108.  
  109. typedef struct StreamStruct    *Stream;
  110.  
  111. typedef struct OOPStruct    *OOP;
  112. typedef struct ObjectStruct    *Object;
  113.  
  114. struct OOPStruct {
  115.   Object    object;
  116.   union {
  117.     struct {
  118. #ifdef BIG_ENDIAN
  119.       unsigned    i_isFree : 1;    /* pack these tighter as needed to make long */
  120.       unsigned  i_evenMark : 1;    /* for OOP table garbage collector */
  121.       unsigned  i_oddMark : 1;    /* for OOP table garbage collector */
  122.       char    i_emptyBytes;   /* 3 number of unused bytes at end; subtract
  123.                    from computed byte length to get the real
  124.                    length of data */
  125.       char    i_inSpace;    /* 0 => space 0, 1 => space 1 */
  126. #else
  127.       char    i_emptyBytes;   /* number of unused bytes at end; subtract
  128.                    from computed byte length to get the real
  129.                    length of data */
  130.       char    i_inSpace;    /* 0 => space 0, 1 => space 1 */
  131.       unsigned    : 13;
  132.       unsigned  i_oddMark : 1;    /* for OOP table garbage collector */
  133.       unsigned  i_evenMark : 1;    /* for OOP table garbage collector */
  134.       unsigned    i_isFree : 1;    /* pack these tighter as needed to make long */
  135. #endif
  136.     } w2_i;
  137. /*    long    w2_prevFree; */
  138.   } w2;
  139. };
  140.  
  141. #define isFree        w2.w2_i.i_isFree
  142. #define emptyBytes    w2.w2_i.i_emptyBytes
  143. #define inSpace        w2.w2_i.i_inSpace
  144. #define evenMark    w2.w2_i.i_evenMark
  145. #define oddMark        w2.w2_i.i_oddMark
  146. /* #define prevFree    w2.w2_prevFree */
  147.  
  148. extern struct OOPStruct  oopTable[];
  149.  
  150. /* The header of all objects in the system */
  151. #define OBJ_HEADER \
  152.   long        objSize; /* for now, this is object size in 32bit words*/ \
  153.   OOP        objClass
  154.  
  155. /* just for symbolic use in sizeof's */
  156. typedef struct ObjectHeaderStruct {
  157.   OBJ_HEADER;
  158. } ObjectHeader;
  159.  
  160. #define OBJ_HEADER_SIZE_WORDS    (sizeof(ObjectHeader) / sizeof(long))
  161.  
  162. struct ObjectStruct {
  163.   OBJ_HEADER;
  164.   OOP        data[1];    /* variable length, may not be objects, but
  165.                    will always be at least this big. */
  166. };
  167.  
  168. extern    OOP        *sp;
  169. extern    char        *nilName;
  170. extern    OOP        nilOOP, trueOOP, falseOOP, thisClass;
  171. extern    Boolean        regressionTesting;
  172.  
  173.  
  174. typedef unsigned char Byte;
  175.  
  176. #define TreeNode        void * /* dummy decl */
  177.  
  178.  
  179. /*
  180.  * Macros for common things...can be functions for debugging or can be 
  181.  * macros for speed.
  182.  */
  183.  
  184. #ifndef NO_INLINE_MACROS
  185.  
  186. #define uncheckedPushOOP(oop) \
  187.   *++sp = (oop)
  188.  
  189. /* YUCK!!!! I HATE TO DO THIS!!!! DAMN GARBAGE COLLECTOR!!!! */
  190. #define pushOOP(oop) \
  191. { \
  192.   OOP __tempOOP = (oop); \
  193.   maybeMoveOOP(__tempOOP); \
  194.   uncheckedPushOOP(__tempOOP); \
  195.  
  196. #define popOOP() \
  197.   (*sp--)
  198.  
  199. #define popNOOPs(n) \
  200.   sp -= (n)
  201.  
  202. #define unPop(n) \
  203.   sp += (n)
  204.  
  205. #define stackTop() \
  206.   (*sp)
  207.  
  208. /* UGH!!! DAMN GC!!!  I wish we could run without it! */
  209. #define setStackTop(oop) \
  210. { \
  211.   OOP __tempOOP = (OOP)(oop); \
  212.   maybeMoveOOP(__tempOOP); \
  213.   *sp = __tempOOP; \
  214. }
  215.  
  216. #define stackAt(i) \
  217.   (sp[-(i)])
  218.  
  219. #define pushInt(i) \
  220.   uncheckedPushOOP(fromInt(i))
  221.  
  222. #define popInt() \
  223.   toInt(popOOP())
  224.  
  225. #define pushBoolean(exp) \
  226.   uncheckedPushOOP((exp) ? trueOOP : falseOOP)
  227.  
  228. #define oopToObj(oop) \
  229.   (oop->object)
  230.  
  231. #define oopClass(oop) \
  232.   (oopToObj(oop)->objClass)
  233.  
  234. #define isClass(oop, class) \
  235.   (isOOP(oop) && oopClass(oop) == class)
  236.  
  237. /* integer conversions */
  238.  
  239. #define toInt(oop) \
  240.   ( (long) ((unsigned long)(oop) - baseInt) )
  241.  
  242. #define fromInt(i) \
  243.   (OOP)(((unsigned long)(i) + baseInt) | highBitMask)
  244.  
  245. /*
  246.  * for these, we could probably get away with just hacking the number and
  247.  * setting the high bit.
  248.  */
  249. #define incrInt(i) \
  250.   fromInt(toInt(i) + 1)
  251.  
  252. #define decrInt(i) \
  253.   fromInt(toInt(i) - 1)
  254.  
  255.  
  256.  
  257. #define isInt(oop) \
  258.   ((long)(oop) < 0)
  259.  
  260. #define isOOP(oop) \
  261.   ((long)(oop) >= 0)
  262.  
  263. /* general functions */
  264.  
  265. #define isNil(oop) \
  266.   ((OOP)(oop) == nilOOP)
  267.  
  268. /* return the number of availble longwords in object, excluding the header */
  269. #define numOOPs(obj) \
  270.   ( 1 + (obj)->objSize - (sizeof(struct ObjectStruct) / sizeof(Object)) )
  271. #endif /* NO_INLINE_MACROS */
  272.  
  273. #endif /* __MST__ */
  274.